Contents

Hide code cell source
import os

import os.path as op

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as sp

from myst_nb import glue 
from IPython.display import HTML

import sys
sys.path.append("../../../functions")
from data_downloaders import download_HOT_CO2_data, download_MLO_CO2_data

sys.path.append("../../../../indicators_setup")
from ind_setup.plotting import plot_timeseries
from ind_setup.plotting_int import plot_timeseries_interactive, fig_int_to_glue
from ind_setup.tables import plot_df_table
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 16
     14 import sys
     15 sys.path.append("../../../functions")
---> 16 from data_downloaders import download_HOT_CO2_data, download_MLO_CO2_data
     18 sys.path.append("../../../../indicators_setup")
     19 from ind_setup.plotting import plot_timeseries

ModuleNotFoundError: No module named 'data_downloaders'
update_data = True
path_data = "../../../data"
path_figs = "../../../matrix_cc/figures"
url = 'https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.txt'

if update_data:
    MLO_data = download_MLO_CO2_data(url)
    MLO_data.to_pickle(op.join(path_data, 'MLO_co2.pkl'))
else:
    MLO_data = pd.read_pickle(op.join(path_data, 'MLO_co2.pkl'))    
MLO_data['CO2_deseasoned'] = MLO_data['CO2'].rolling(window=12, center=True).mean()
glue("n_years", len(np.unique(MLO_data.index.year)), display=False)
glue("co2_2024", int(MLO_data.loc['2024'].CO2.mean()), display=False)
glue("start_year", MLO_data.dropna().index[0].year, display=False)
dict_plot = [{'data' : MLO_data, 'var' : 'CO2', 'ax' : 1, 'trendline' : True, 'label' : 'MLO: CO2'},
             {'data' : MLO_data, 'var' : 'CO2_deseasoned', 'ax' : 1, 'trendline' : False, 'label' : 'MLO: CO2 (Deseasoned)'}]
fig, trend = plot_timeseries_interactive(dict_plot, trendline=True, figsize=(20, 10), return_trend=True);
fig.write_html(op.join(path_figs, 'F1_CO2_trend.html'), include_plotlyjs="cdn")


glue("trend", float(trend[0]), display=False)
glue("change", float(trend[0]*len(np.unique(MLO_data.index.year))), display=False)
glue("trend_fig", fig_int_to_glue(fig), display=False)
Hide code cell source
MLOy = MLO_data[['CO2']].groupby(MLO_data.index.year).mean()
MLOy.index = pd.to_datetime(MLOy.index, format = '%Y')
d = MLOy.describe()
d.loc['Rate of change'] = trend
fig = plot_df_table(np.round(d, 2), figsize = (400, 400))
../../../../../../_images/f7f9d5002480dd232f7bacc1ed023922b2df50c51d9768b7cd16d6d700cce4b3.png